<template>
	<view class="container">
		<!-- <view class="cooperation">
			<view class="name">
				<view class="" style="width: 36rpx; height: 36rpx;border-radius: 50%;margin-right: 20rpx;overflow: hidden;background-color: #fff;">
					<image :src="shopDetailInfo.avatar" mode="widthFix" style="width: 36rpx;"></image>
				</view> 
				<view class="">
					{{shopDetailInfo.shopname}}
				</view>
			</view>
			<view class="btn_view">
				<button type="button" class="btn" @click="toCooperationApply">合作申请</button>
			</view>
		</view> -->
		<image src="/static/banner_1.png" mode="widthFix" style="width: 100vw;"></image>
		<view class="shop_info">
			<view class="shop_name">
				<view class="name">
					{{shopDetailInfo.shopname}}
				</view>
				<!-- 暂时去除 -->
				<!-- <view class="collection">
					<image src="/static/icon_collection.png" mode="widthFix" style="width: 56rpx;height: 56rpx;"></image>
				</view> -->
			</view>
			<view class="shop_time">
				<view class="time">
					{{shopDetailInfo.bio}}
				</view>
				<view class="shop_label">
					<view class="settle_in">
						<view class="title"> {{shopDetailInfo.in_years}} </view>
						<view class="value"> 入驻{{shopDetailInfo.in_years}}年 </view>
					</view>
					<view class="equip_num">
						康养设备{{shopDetailInfo.devices_number}}台
					</view>
				</view>
			</view>
			<view class="address_info">
				<view class="address">
					{{shopDetailInfo.address}}
				</view>
				<view class="options">
					<view class="option" @click="navigate">
						<image src="/static/icon_shop_location.png" mode="widthFix" style="width: 48rpx;height: 48rpx;"></image>
						<view class="name">导航</view>
					</view>
					<view class="option" @click="makePhoneCall">
						<image src="/static/icon_shop_mobile.png" mode="widthFix" style="width: 48rpx;height: 48rpx;"></image>
						<view class="name">电话</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="tabs">
			<uni-segmented-control :current="activeCateIndex" :values="items" style-type="text" active-color="#FA2C1E" @clickItem="chageActiveCateIndex"  style="background-color: #fff;"/>
		</view>
		<!-- <view class="tabs">
			<view class="tab" :class="{'active':activeCateIndex==index}" v-for="(cate,index) in cateListData" :key="cate.name" @click="chageActiveCateIndex(index)">
				{{cate.name}}
			</view>
		</view> -->
		<view class="goods">
			<view v-if="goodsList.length <= 0" style="height: 100rpx; display: flex;justify-content: center;align-items: center;font-size: 26rpx;">
				暂无产品
			</view>
			<view v-else>
				<view class="goods_item" v-for="(item,index) in goodsList" :key="index" @click="toDetail(item)" >
					<view class="goods_img">
						<image :src="item.image" class="img" style="width: 120rpx;height: 120rpx;"></image>
					</view>
					<view class="right">
						<view class="name">
							{{item.title}}
						</view>
						<!-- <view class="labels">
							<view class="label" v-for="(label,i) in item.label_ids" :key="label">
								{{label}}
							</view>
						</view> -->
						<view class="price">
							￥{{item.price}}
						</view>
					</view>
					<view class="sale_num">
						已售{{item.sales}}
						<image src="/static/right.png" mode="widthFix" style="width: 16rpx;height: 16rpx;margin-left: 14rpx;"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 暂时去除 -->
		<!-- <view class="equip_service">
			<view class="title">
				设备与服务
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in deviceServiceList" :key="item.id">
					<image :src="item.image" mode="widthFix"></image>
					<view class="name">
						{{item.title}}
					</view>
				</view>
			</view>
			<view class="more">
				查看全部设施与服务
				<image src="/static/right.png" mode="widthFix" style="width: 20rpx;height: 20rpx;margin-left: 14rpx;"></image>
			</view>
		</view> -->
	</view>
</template>

<script>
	import {shopGoodsList,goodsList,cateList,shopDetail,getDeviceServiceInfo} from '../../api/api.js'
	export default {
		data() {
			return {
				shop_id:'',
				shopDetailInfo:{},
				goodsList:[],
				deviceServiceList:[],
				activeCateIndex:0,
				cateListData:[
					{ id:83,name:'美的产品' },
					{ id:84,name:'康养产品' }
				],
				items:[ '美的产品','康养产品' ]
			}
		},
		onLoad(options){
			this.shop_id = options.shopId
			// this.getCateList()
			this.shopDetail()
			this.shopGoodsList()
			// this.getDeviceServiceInfo()
		},
		methods:{
			/**
			 * 切换商品类别
			 * @param {Object} e
			 */
			chageActiveCateIndex(e){
				if(this.activeCateIndex != e.currentIndex){
					this.activeCateIndex = e.currentIndex
					this.shopGoodsList()
				}
			},
			/**
			 * 合作申请（一期接口）
			 */
			toCooperationApply(){
				uni.navigateTo({url:'/pages/shop/cooperationApply/cooperationApply?shopId='+this.shop_id})
			},
			/**
			 * 明细
			 * @param {Object} goods
			 */
			toDetail(goods){
				console.log('toDetail')
				uni.navigateTo({url:'/pages/shop/setMealDetail?shopId='+this.shop_id+'&goodsId='+goods.id+'&shopname=' + this.shopDetailInfo.shopname})
			},
			/**
			 * 店铺详情
			 */
			shopDetail(){
				shopDetail({shop_id:this.shop_id}).then(res=>{
					this.shopDetailInfo = res.data.data || {}
				})
			},
			/**
			 * 设备与服务（二期接口，暂时停用）
			 */
			getDeviceServiceInfo(){
				getDeviceServiceInfo().then(res=>{
					this.deviceServiceList = res.data.data
				})
			},
			/**
			 * 分类列表（一期接口）
			 */
			getCateList(){
				cateList().then(res=>{
					console.log(res)
					this.cateListData = res.data.data
					this.items = this.cateListData.map(c=>c.name)
					if(this.cateListData.length > 0){
						this.getGoodsList()
					}
				})
			},
			/**
			 * 商品列表（一期接口）
			 */
			getGoodsList(){
				goodsList({cate_id:this.cateListData[this.activeCateIndex].id,shop_id:this.shop_id}).then(res=>{
					console.log(res)
					this.goodsList = res.data.data.data
				})
			},
			/**
			 * 商品列表（二期接口）
			 */
			shopGoodsList(){
				shopGoodsList({shop_category_id:this.cateListData[this.activeCateIndex].id,shop_id:this.shop_id}).then(res=>{
					console.log(res.data.data)
					this.goodsList = res.data.data
				})
			},
			/**
			 * 导航
			 */
			navigate(){
				let that = this
				uni.openLocation({
					latitude: Number(that.shopDetailInfo.latitude),
					longitude: Number(that.shopDetailInfo.longitude),
					address: that.shopDetailInfo.address,
					name: that.shopDetailInfo.shopname,
					success: function () {
						console.log('success');
					},
					fail: function(e){
						console.log(e)
					}
				});
			},
			/**
			 * 电话
			 */
			makePhoneCall(){
				uni.makePhoneCall({
					phoneNumber:this.shopDetailInfo.mobile.toString(),//电话号码
					success:function(e){
						console.log(e);
					},
					fail:function(e){
						console.log(e);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #F8F8F8;
		min-height: calc(100vh - env(safe-area-inset-top));
		overflow: scroll;
	}
	.cooperation {
		width: 100%;
		// height: 232rpx;
		background-image: url(../../static/hezuoguanxi.png);
		background-size: 100% 100%;
		padding: 30rpx;
		.name {
			font-size: 28rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
			line-height: 40rpx;
			padding: 18rpx;
			display: flex;
			align-items: center;
		}
		.btn {
			margin-top: 10rpx;
			height: 88rpx;
			background: #FFFFFF;
			border-radius: 44rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FA2C1E;
		}
	}

	.shop_info {
		background-color: #fff;
		width: 100%;
		padding: 30rpx;
		.shop_name {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
			line-height: 50rpx;
			padding-bottom: 26rpx;
			border-bottom: 2rpx solid #E7E7E7;
			.collection {
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
		.shop_time {
			margin-top: 18rpx;
			border-bottom: 2rpx solid #E7E7E7;
			.time {
				font-size: 24rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 34rpx;
			}
			.shop_label {
				margin-top: 10rpx;
				padding-bottom: 20rpx;
				display: flex;
				align-items: center;
				font-size: 20rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				.settle_in {
					height: 32rpx;
					background: #FFEDDD;
					border-radius: 16rpx;
					padding-right: 24rpx;
					color: #8F3C12;
					display: flex;
					align-items: center;
					.title {
						background-image: url(/static/settle_in_year_bg.png);
						background-repeat: no-repeat;
						background-position: left top;
						background-size: auto 100%;
						height: 32rpx;
						width: 56rpx;
						text-align: center;
						margin-right: 8rpx;
						padding-right: 4rpx;
						font-weight: 500;
						color: #591C00;
					}
				}
				.equip_num {
					background: #F4F4F4;
					border-radius: 8px 8px 8px 0px;
					padding: 0 20rpx;
					margin-left: 24rpx;
				}
			}
		}
		.address_info {
			padding-top: 24rpx;
			font-size: 26rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
			line-height: 36rpx;
			display: flex;
			align-items: center;
			.address {
				width: calc(100% - 204rpx);
			}
			.options {
				width: 144rpx;
				margin-left: 60rpx;
				display: flex;
				justify-content: space-between;
				.option .name {
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}
			}
		}
	}
	.tabs {
		background-color: #fff;
		margin-top: 20rpx;
		padding-left: 24rpx;
		// /deep/ .segmented-control {
		// 	width: 300rpx;
		// }
		/deep/ .segmented-control__item {
			flex: none;
			margin-right: 18rpx;
		}
	}
	

	/* .tabs {
		background-color: #fff;
		width: 100%;
		height: 88rpx;
		padding: 8rpx 24rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 36rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FA2C1E;
		line-height: 50rpx;
		.tab {
			width: 340rpx;
			border-radius: 8rpx;
			height: 72rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.active {
			background: #FA2C1E;
			color: #FFFFFF;
		}
	}
 */
	.goods {
		padding: 0 24rpx;
		background-color: #fff;
		.goods_item {
			width: 100%;
			// height: 180rpx;
			// margin-bottom: 20rpx;
			display: flex;
			border-bottom: 2rpx solid #EEEEEE;
			padding: 26rpx 0;
			position: relative;
			.goods_img {
				width: 120rpx;
				height: 120rpx;
				border-radius: 10rpx;
				background-color: red;
				.img {
					width: 120rpx;
					height: 120rpx;
				}
			}
			.right {
				padding: 0 20rpx;
				width: calc(100% - 120rpx);
				height: 120rpx;
				text-shadow: 0px 4rpx 30rpx rgba(0,0,0,0.05);
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.name {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
					line-height: 34rpx;
				}
				/* .labels {
					width: 100%;
					margin-top: 26rpx;
					display: flex;
					.label {
						font-size: 18rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #FA2C1E;
						line-height: 30rpx;
						background: #FFFFFF;
						box-shadow: 0px 4rpx 30rpx rgba(0,0,0,0.05);
						border-radius: 6rpx;
						border: 2rpx solid #FA2C1E;
						margin-right: 8rpx;
						padding: 4rpx 16rpx;
					}
				} */
				.price {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FA2C1E;
					line-height: 50rpx;
				}
			}
			.sale_num {
				position: absolute;
				right: 0;
				bottom: 26rpx;
				display: flex;
				align-items: center;
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				// line-height: 36rpx;
			}
		}
		.goods_item:last-child{
			border-bottom:none;
		}
	}
	.equip_service {
		background-color: #fff;
		padding: 24rpx 30rpx;
		margin-top: 20rpx;
		.title {
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
			line-height: 44rpx;
			margin-top: 10rpx;
			margin-bottom: 24rpx;
		}
		.list {
			display: flex;
			border-bottom: 2rpx solid #EEEEEE;
			padding-bottom: 26rpx;
			height: 100%;
			.item {
				// flex: 1;
				width: 30%;
				// height: 100%;
				
				margin-right: 24rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				image {
					height: calc(30vw - 36rpx);
					width: 100%;
				}
				.name {
					margin-top: 26rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
					line-height: 40rpx;
				}
			}
			.item:last-child {
				margin: 0;
			}
		}
		.more {
			margin-top: 22rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #666666;
			line-height: 40rpx;
		}
	}
</style>
